package com.stylefeng.guns.modular.biz.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.ItemAttribute;
import com.stylefeng.guns.modular.biz.service.IItemAttributeService;

/**
 * 商品属性控制器
 *
 * @author fengshuonan
 * @Date 2018-09-28 18:23:04
 */
@Controller
@RequestMapping("/itemAttribute")
public class ItemAttributeController extends BaseController {

    private String PREFIX = "/biz/itemAttribute/";

    @Autowired
    private IItemAttributeService itemAttributeService;

    /**
     * 跳转到商品属性首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "itemAttribute.html";
    }

    /**
     * 跳转到添加商品属性
     */
    @RequestMapping("/itemAttribute_add")
    public String itemAttributeAdd() {
        return PREFIX + "itemAttribute_add.html";
    }

    /**
     * 跳转到修改商品属性
     */
    @RequestMapping("/itemAttribute_update/{itemAttributeId}")
    public String itemAttributeUpdate(@PathVariable Integer itemAttributeId, Model model) {
        ItemAttribute itemAttribute = itemAttributeService.selectById(itemAttributeId);
        model.addAttribute("item",itemAttribute);
        LogObjectHolder.me().set(itemAttribute);
        return PREFIX + "itemAttribute_edit.html";
    }

    /**
     * 获取商品属性列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return itemAttributeService.selectList(null);
    }

    /**
     * 新增商品属性
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(ItemAttribute itemAttribute) {
        itemAttributeService.insert(itemAttribute);
        return SUCCESS_TIP;
    }

    /**
     * 删除商品属性
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer itemAttributeId) {
        itemAttributeService.deleteById(itemAttributeId);
        return SUCCESS_TIP;
    }

    /**
     * 修改商品属性
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(ItemAttribute itemAttribute) {
        itemAttributeService.updateById(itemAttribute);
        return SUCCESS_TIP;
    }

    /**
     * 商品属性详情
     */
    @RequestMapping(value = "/detail/{itemAttributeId}")
    @ResponseBody
    public Object detail(@PathVariable("itemAttributeId") Integer itemAttributeId) {
        return itemAttributeService.selectById(itemAttributeId);
    }
}
